<template>
  <el-main height="">
    <!-- 按钮 -->
    <el-form :inline="true" size="small">
      <el-form-item>
        <el-button
          type="primary"
          v-permission="['sys:menu:add']"
          @click="addBtn"
          :icon="Plus"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      :height="tableHeight"
      :data="menuTable.list"
      style="width: 100%"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="label" label="菜单名称" />
      <el-table-column prop="type" label="类型" align="center">
        <template #default="scope">
          <el-tag v-if="scope.row.type == '0'">目录</el-tag>
          <el-tag v-if="scope.row.type == '1'" type="success">菜单</el-tag>
          <el-tag v-if="scope.row.type == '2'" type="danger">按钮</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="label" label="图标" align="center">
        <template #default="scope">
          <!-- <Icon class="icons" :icon="scope.row.icon">{{scope.row.icon}}</Icon> -->
          <component class="icons" :is="scope.row.icon"></component>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="路由名称" />
      <el-table-column prop="path" label="路由地址" />
      <el-table-column prop="url" label="组件路径" />
      <el-table-column label="操作" width="210" align="center">
        <template #default="scope">
          <el-button
            type="primary"
            size="small"
            @click="editBtn(scope.row)"
            :icon="Edit"
            v-permission="['sys:menu:edit']"
            >编辑</el-button
          >
          <el-button
            type="danger"
            size="small"
            @click="deleteBtn(scope.row.id)"
            :icon="Close"
            v-permission="['sys:menu:delete']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </el-main>
  <!-- 新增编辑弹框 -->
  <AddMenuVue ref="addMenuRef" @save="save"></AddMenuVue>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick } from 'vue'
import { Plus, Edit, Close } from '@element-plus/icons-vue'
// 引入表格的数据，表格数据的获取和存储
import useMenuTable from '@/composables/menu/useMenuTable'
// 引入对整体页面的操作方法，表格的增删改查
import useMenu from '@/composables/menu/useMenu'
import AddMenuVue from './AddMenu.vue'
//表格的高度
const tableHeight = ref(0)
const { menuTable, getMenuTable } = useMenuTable()
const { addBtn, deleteBtn, editBtn, save, addMenuRef } = useMenu(getMenuTable)
onMounted(() => {
  nextTick(() => {
    tableHeight.value = window.innerHeight - 200
  })
})
</script>
<style scoped lang="scss">
.icons {
  width: 24px;
  height: 18px;
  margin-right: 5px;
}
</style>
